Sound Commands


Either you're making multimedia presentation or player, sound features are important part of entire story. MMB comes with variety of sound-related script commands, dealing with:

  •   Audio Volume
  •   Sound playback of following formats:
      MPG, MP1, MP2, MP3, OGG, WMA, ASF, WAV, MID, RMI, MOD, S3M, XM, IT
  •   Audio CD playback
  •   Audio Visualization

Volume Commands


VolumeUp("Volume")
Description
 


Increases Master Volume by 5% if no percentage is specified through command parameter.

Otherwise sets volume to specified percentage value in range:

0-100

Code Exampless
 

**Increase volume without custom percentage:
VolumeUp()

**Set volume to 70%:
VolumeUp("70")

**Set volume to 20% using numerical variable:
volume=20
VolumeUp(
"volume")

Additional Info
 
Master volume is an output audio volume for all mixer lines.

 

VolumeDown()
Description
 


Decreases Master Volume by 5% . No parameters required.

Code Example
 

**Decrease Master Volume:
VolumeDown()

Additional Info
 
Master volume is an output audio volume for all mixer lines.

 

Sound Playback Commands

 

FMODConfig("Parameters")
Description
 


Displays FMOD library configuration dialog box, giving users ability to set output sound driver and device. MMB also allows setting configuration through this script command. If you call FMODConfig command without parameters...

FMODConfig("")

...configuration dialog box will appear:

 

As already mentioned alternative, configuration can be set through FMODConfig command itself using parameters, thus avoiding configuration dialog box. There are two parameters separated with comma.

With first one you set sound output driver using one of following numbers:

1 - DirectX sound
2 - Windows Media Wave Out
3 - No Sound

With second parameter you set status of MPEG accurate VBR ( Variable Bit Rate) timing:

0 - MPEG accurate VBR timing off
1 - MPEG accurate VBR timing on

Put into command, parameters look like this:

FMODConfig("1,0")

In example above, green number represents sound output driver setting.
Red number represents status of MPEG accurate VBR timing.

Code Examples
 

**Show FMOD library configuration dialog box:
FMODConfig("")

**Set configuration to Windows Media Wave output driver with
**MPEG accurate VBR timing off:

FMODConfig("2,0")

**Set configuration to DirectX Sound output driver with
**MPEG accurate VBR timing on:

FMODConfig("2,1")

Additional Info
 
Configuration dialog box is displayed on top and project's window can't be used until user closes dialog box.

 

PlaySound("Path")
Description
 


Plays any supported type of sound file (MP3, Ogg, WMA, ASF, Wave, MOD, MIDI) specified as command parameter.

Sound file parameter should contain either

a) folder path + sound file name, or
b) path macro + sound file name

Code Examples
 

**Play MP3 sound file MyMusic.mp3 from folder c:\My Project
PlaySound("c:\My Project\MyMusic.mp3")

**Play WAVE sound file tada.wav from Window's media folder:
PlaySound("<Windows>\Media\tada.wav")

**Play MIDI sound file Autumn.mid from <SrcDir> folder:
PlaySound("<SrcDir>\Autumn.mid")

Additional Info
 
Use CBK contants to retrieve info on opened sound file.

 

StopSound()
Description
 

Stops sound playback.

This command not only stops playback of all audio files but it also unload the files from memory.

No parameters required.

Code Example
 

**Stop sound playback:
StopSound()

Additional Info
 
This command stops playback of all sound files, including background sound (if used).

 

AudioOpen("Path")
Description
 


Opens and plays MP3, OGG, WMA or ASF sound file specified as a command parameter.

Sound file parameter should contain either

a) folder path + sound file name, or
b) path macro + sound file name

Code Examples
 

**Play MP3 sound file MyMusic.mp3 from folder c:\My Project
AudioOpen("c:\My Project\MyMusic.mp3")

**Play WMA sound file FourSeasons.wma from <SrcDir> folder:
AudioOpen("<SrcDir>\FourSeasons.wma")

Additional Info
 

Use CBK contants to retrieve info on opened sound file.

If file has not been specified as a command parameter, MMB will display Open File dialog box. Multiple file selections are enabled (using CTRL and SHIFT keys) - first selected file will be played, others are stored in MMB's internal Song List and are retrievable through the <List> constant.

 

AudioPlay()
Description
 


Plays MP3, OGG, WMA or ASF sound file specified using AudioOpen command.

Code Example
 

**Play opened sound
AudioPlay( )

Additional Info
 
Use CBK contants to retrieve info on played sound file.

 

AudioStop()
Description
 

Stops playback of sound opened and played by either AudioOpen or AudioPlay command.

No parameters required.

Code Example
 

**Stop sound playback:
AudioStop()

 

AudioPause()
Description
 

Pauses playback of sound opened and played by either AudioOpen or AudioPlay command.

No parameters required.

Code Example
 

**Pause sound playback:
AudioPause()

 

AudioRewind("Time","Parameters")
Description
 


Rewinds sound opened and played by either AudioOpen or AudioPlay command to a given position (in seconds).

First command parameter sets number of seconds for rewinding.

Second command parameter is optional, used for relative rewinding, and to use it set:

RELATIVE

...as a second command parameter.

Code Examples
 

**Rewind audio file to 125th second
AudioRewind("125","")

**Rewind audio file for 20 seconds using relative rewinding
AudioRewind("20","RELATIVE")

Additional Info
 

Learn about Matrix object to create a seek bar.

 

BackgroundPlay("Path","Parameters")
Description
 


Opens and plays any type of supported sound file, specified as command parameter, as background sound.

First command parameter requires either

a) folder path + sound file name, or
b) path macro + sound file name

Second command parameter is optional and with it you can loop (automatically repeat) playback of specified sound file. Parameter is:

LOOP

Code Examples
 

**Background play MP3 sound file MyMusic.mp3 from <SrcDir> folder
BackgroundPlay("<SrcDir>\MyMusic.mp3","")

**Background play WAV sound file Beat.wav from <CD> folder in loop
BackgroundPlay("<CD>\Beat.wav","LOOP")

Additional Info
 

Use CBK contants to retrieve info on played sound file.

 

BackgroundPause()
Description
 

Pauses playback of sound opened and played by BackgroundPlay command.

No parameters required.

Code Example
 

**Pause background sound playback:
BackgroundPause()

 

BackgroundStop()
Description
 

Stops playback of sound opened and played by BackgroundPlay command.

No parameters required.

Code Example
 

**Stop background sound playback:
BackgroundStop()

 

WavePlay("Path","Parameters")
Description
 


Opens and plays WAVE sound file specified as a command parameter.

First command parameter requires either

a) folder path + sound file name, or
b) path macro + sound file name

Second command parameter is optional and with it you can loop (automatically repeat) playback of specified sound file. Parameter is:

LOOP

Code Examples
 

**Play file MyMusic.wav from folder c:\My Project
WavePlay("c:\My Project\MyMusic.wav")

**Play file FourSeasons.wav from <SrcDir> folder with looping:
WavePlay("<SrcDir>\FourSeasons.wav","LOOP")

**In case of sound file is embedded, don't use the full path..just name of embedded file defined in the "Embedded Sounds" dialog:
WavePlay("FourSeasons","")

Additional Info
 

Use CBK contants to retrieve info on opened sound file.

If file has not been specified as command parameter, MMB will display Open File dialog box. Multiple file selections are enabled (using CTRL and SHIFT keys) - first selected file will be played, others are stored in MMB's internal Song List and are retrievable through the <List> constant.

 

WaveStop()
Description
 

Stops playback of sound opened and played by WavePlay command.

No parameters required.

Code Example
 

**Stop wave sound playback:
WaveStop()

 

MidiPlay("Path","Parameters")
Description
 


Opens and plays MIDI sound file specified as command parameter.

First command parameter requires either

a) folder path + sound file name, or
b) path macro + sound file name

Second command parameter is optional and with it you can loop (automatically repeat) playback of specified sound file. Parameter is:

LOOP

Code Examples
 

**Play file MyMusic.mid from folder c:\My Project
MidiPlay("c:\My Project\MyMusic.mid")

**Play file FourSeasons.mid from <SrcDir> folder with looping:
MidiPlay("<SrcDir>\FourSeasons.mid","LOOP")

Additional Info
 

Use CBK contants to retrieve info on opened sound file.

If file has not been specified as command parameter, MMB will display Open File dialog box. Multiple file selections are enabled (using CTRL and SHIFT keys) - first selected file will be played, others are stored in MMB's internal Song List and are retrievable through the <List> constant.

 

MidiStop()
Description
 

Stops playback of sound opened and played by MidiPlay command.

No parameters required.

Code Example
 

**Stop midi sound playback:
MidiStop()

 

ModOpen("Path")
Description
 


Opens MOD sound file specified as command parameter.

Parameter requires either

a) folder path + sound file name, or
b) path macro + sound file name

Code Examples
 

**Open file MyMusic.mod from folder c:\My Project
ModOpen("c:\My Project\MyMusic.mod")

**Open file FourSeasons.mod from <SrcDir> folder
ModOpen(" <SrcDir>\FourSeasons.mod")

Additional Info
 

Use CBK contants to retrieve info on opened sound file.

If file has not been specified as command parameter, MMB will display Open File dialog box. Multiple file selections are enabled (using CTRL and SHIFT keys) - first selected file will be played, others are stored in MMB's internal Song List and are retrievable through the <List> constant.

 

ModPlay()
Description
 

Plays MOD file opened using ModOpen command.

No parameters required.

Code Example
 

**Play MOD file:
ModPlay()

 

ModStop()
Description
 

Stops playback of sound opened and played using ModOpen and ModPlay commands.

No parameters required.

Code Example
 

**Stop MOD sound playback:
ModStop()

 

Audio CD Playback Commands

 

CDPlay()
Description
 


Starts playback of Audio CD from the start.

Code Example
 

**Play Audio CD from the start
CDPlay()

Additional Info
 
Use CBK contants to retrieve info about Audio CD.

 

CDStop()
Description
 


Stops playback of Audio CD.

Code Example
 

**Stop Audio CD playback
CDStop()

 

CDPause()
Description
 


Pause playback of current Audio CD track.

Code Example
 

**Pause Audio CD playback
CDPause()

 

CDTrack("Track")
Description
 


Plays Audio CD track specified using command parameter.

Parameter sets number of track, for example:

4

...will play Track 4.

Code Example
 

**Play Audio CD track no. 6
CDTrack("6")

Additional Info
 

Mixed-mode CD's use first track for data, so first audio track is Track 2.

 

CDForward()
Description
 


Plays next Audio CD track.

Code Example
 

**Play next CDDA track
CDForward()

 

CDBackward()
Description
 


Plays previous Audio CD track.

Code Example
 

**Play previous CDDA track
CDBackward()

 

CDPlayPause()
Description
 


Pauses or plays Audio CD.

If playback has been paused/stopped, it will be resumed. Otherwise playback is paused.

Useful when making one button for play/pause functions.

Code Example
 

**Play or pause Audio CD
CDPlayPause()

 

CDSkipForward()
Description
 


Sets position of currently played Audio CD track 10 seconds forward.

Code Example
 

**Forward current Audio CD track
CDSkipForward()

 

CDSkipBackward()
Description
 


Sets position of currently played Audio CD track 10 seconds backward.

Code Example
 

**Backward current Audio CD track
CDSkipBackward()

 

WhichCDTrack("TrackVar")
Description
 


Retrieves number of currently played Audio CD track and puts result into numerical variable specified as command parameter.

Parameter sets numerical variable that will contain numer of played track.

For example:

TrackNo

...when put into command, it looks like this:

WhichCDTrack("TrackNo")

After performing code line above, numerical variable TrackNo will contain number of played audio track. You can now, for example, display it:

Message("Current Audio CD track:","TrackNo")

Code Example
 

**Retrieve number of currently played Audio CD track and display result
**in text object labeled "AudioTrack":

WhichCDTrack("TrackNo")
DisplayValue("AudioTrack","TrackNo")

Additional Info
 

Mixed-mode CD's use first track for data, so first audio track is Track 2.

 

Audio Visualization Commands

 

AudioVisualizationType("ObjectLabel","Type")
Description
 


Sets type of Audio Visualization.

Uses two parameters - first parameter sets label of Audio Visualization object you want settings be applied to. For example,

AudioVis

Second parameter sets visualization type:

  • ANALYZER


  • OSCILLOSCOPE

Code Examples
 

**Set audio visualization object labeled MyVis to ANALYZER:
AudioVisualizationType("MyVis","ANALYZER")

**Set audio visualization object labeled AudioVis to
**OSCILLOSCOPE:

AudioVisualizationType("AudioVis","OSCILLOSCOPE")

Additional Info
 

Audio visualization is supported for MP3, OGG, WAV, XM, S3M, IT, MOD files.

 

AudioVisualizationColor("ObjectLabel","Parameters")
Description
 


Sets color of Audio Visualization elements.

First parameter sets label of Audio Visualization object you want settings be applied to. For example,

AudioVis

Second parameter sets visualization color.

Color setting uses RGB ( Red, Green, Blue) system containing 3 components.

Each component can have one of 256 levels. Greater value of component increases color intensity. If you specify value 0, color component will not be used. Value 255 uses maximum color intensity.

Color parameter for Audio Visualization is a comma-separated array of string values, each representing one RGB component (first: red, second: green, third: blue) in value range 0-255.

R,G,B
Result
128,5,64
 

R,G,B
Result
0,255,255
 

 

Both Analyzer and Oscilloscope visualizations have background color

that can be changed using following parameter:

BACKGROUND=R,G,B

Put with numerical RGB values:

BACKGROUND= 150, 79, 205


Analyzer visualization uses two color settings:

First you set RGB values for bar color:

RGB(255,0,0)

And after comma, add RGB values for peak color:

RGB(0,0,255)

Put together, second parameter for analyzer looks like this:

RGB(255,0,0),RGB(0,0,255)

Oscilloscope visualization uses only one (line) color setting:


Example of RGB values for oscilloscope line color:

RGB(255,0,0)

Code Examples
 

**Set background color of Audio Visualization object labeled AudioVis:
AudioVisualizationColor("AudioVis","BACKGROUND=150,79,205")

**Set Analyzer bar and peak colors of Audio Visualization object
**labeled AudioVis:

AudioVisualizationColor("AudioVis","255,0,0,0,0,255")

**Set Oscilloscope line color of Audio Visualization object labeled AudioVis:
AudioVisualizationColor("AudioVis","255,0,0")

** an advanced example with ColorPicker()
BGColor$=''
ColorPicker()
BGColor$=CBK_SelColor
If (BGColor$>'') Then
  AudioVisualizationColor("AudioVisualization","BACKGROUND=CBK_SelColor")
End

It opens "Select Color" dialog and allow you to select a color, then replace the current BG color with new selected.

Additional Info
 

Audio visualization is supported for MP3, OGG, WAV, XM, S3M, IT, MOD files.

 


MMB Scripting Unleashed by Bokzy, 2003 :: All rights reserved :: http://www.bokzy.com